<template>
    <div>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb-base" style="line-height: 30px">
            <el-breadcrumb-item>
                <font-awesome-icon :icon="['fas', 'home']"></font-awesome-icon>
                院内诊断
            </el-breadcrumb-item>
        </el-breadcrumb>

        <div class="main-container">
            <el-row class="pad-box">
                <div
                style="
                    position: absolute;
                    top: 0;
                    right: 0;
                    cursor: pointer;
                    color: #00be8b;
                    font-size: 22px;
                "
                @click="goPc"
                >
                    <el-tooltip content="切换到电脑版" placement="top">
                        <i class="el-icon-monitor"></i>
                    </el-tooltip>
                </div>
                <div class="grid-content bg-purple" @click="toDataList(1)">
                <div class="box-left">
                    <img src="@/client/assets/images/pad/taskPoolIcon.png" alt="" />
                    <span>任务池</span>
                </div>
                <div :class="[waitingAssignCount > 0 ? 'redClass' : 'normalClass', 'num']">
                    <span>{{ waitingAssignCount > 0 ? waitingAssignCount : 0 }}</span>
                </div>
                </div>
                <div class="grid-content bg-purple" @click="toDataList(2)">
                <div class="box-left">
                    <img src="@/client/assets/images/pad/myIssuesIcon.png" alt="" />
                    <span>我的任务</span>
                </div>
                <div :class="[myIssuesCount > 0 ? 'redClass' : 'normalClass', 'num']">
                    <span>{{ myIssuesCount > 0 ? myIssuesCount : 0 }}</span>
                </div>
                </div>
                <div class="grid-content bg-purple" @click="toDataList(3)">
                <div class="box-left">
                    <img src="@/client/assets/images/pad/myInvitedIcon.png" alt="" />
                    <span>我已承接</span>
                </div>
                <div :class="[myAssignedCount > 0 ? 'redClass' : 'normalClass', 'num']">
                    <span>{{ myAssignedCount > 0 ? myAssignedCount : 0 }}</span>
                </div>
                </div>
                <div class="grid-content bg-purple" @click="toDataList(4)">
                <div class="box-left">
                    <img src="@/client/assets/images/pad/myFinishIcon.png" alt="" />
                    <span>科内会诊</span>
                </div>
                <div :class="[divisionConsultationCount > 0 ? 'blueClass' : 'normalClass', 'num']">
                    <span>{{ divisionConsultationCount > 0 ? divisionConsultationCount : 0 }}</span>
                </div>
                </div>
                <div class="grid-content bg-purple" @click="toDataList(5)">
                <div class="box-left">
                    <img src="@/client/assets/images/pad/myFinishIcon.png" alt="" />
                    <span>院外会诊</span>
                </div>
                <div :class="[outsideConsultationCount > 0 ? 'blueClass' : 'normalClass', 'num']">
                    <span>{{ outsideConsultationCount > 0 ? outsideConsultationCount : 0 }}</span>
                </div>
                </div>
            </el-row>
        </div>
    </div>
</template>

<script>
import _ from 'lodash';
import BaseTable from '@templates/components/BaseTable';

import moment from 'moment/moment';
import { itemsPerPage, itemsDiagnosisListPage } from '@/client/libs/util';
import { DateUtil } from '@/client/libs/date';

import NormalDetail from '@templates/components/NormalDetail';

export default {
    name: 'DiagnosisPadList',
    components: {
        BaseTable,
        NormalDetail,
    },
    data() {
        return {
            listTabActive: 'myIssues',
            isFullScreen: false,
            selectedList: [], // 多选 全选 数据
            tabCountRequestList: [
                {
                    url: '/diagnosis/wait-dispatch',
                    countKey: 'waitingAssignCount',
                },
                {
                    url: '/diagnosis/tasks',
                    countKey: 'myIssuesCount',
                },
                {
                    url: '/diagnosis/finished',
                    countKey: 'myAssignedCount',
                },
            ],
            consultationRequestList: [
                {
                    url: '/diagnosis/divisionConsultation',
                    countKey: 'divisionConsultationCount',
                    judgeDivisionOrOutside: 0,
                },
                {
                    url: '/diagnosis/divisionConsultation',
                    countKey: 'outsideConsultationCount',
                    judgeDivisionOrOutside: 1,
                },
            ],

            waitingAssignCount: 0,
            divisionConsultationCount: 0,
            outsideConsultationCount: 0,
            myIssuesCount: 0,
            myAssignedCount: 0,

            diagnosisTable: {
                selected: false,
                isReady: false,
                data: [
                    {
                        id: 276,
                        pathologyId: '1234',
                    },
                ],
                header: [
                    {
                        label: '倒计时',
                        prop: 'createTime',
                        width: '120',
                        isRender: true,
                        render: (h, params) => {
                            let _vm = this;
                            let _c = _vm._self._c || _h;
                            let currentTime = _vm.freezeAndCommonTimeList.find(
                                (item) => {
                                    return (
                                        item.name === params.row.freezeTypeName
                                    );
                                }
                            );
                            if (!currentTime || currentTime.name === '常规') {
                                currentTime = _vm.specimenCategoryTimeList.find(
                                    (item) => {
                                        return (
                                            item.name ===
                                            params.row.specimenTypeName
                                        );
                                    }
                                );
                            }
                            const hour = currentTime
                                ? parseFloat(currentTime.firstCode)
                                : undefined;
                            let dateContent = null;
                            let offsetTime = null;
                            if (hour) {
                                //冰冻按取回的琅珈冰冻时间计算  如果冰冻时间为空再取本系统的匹配时间
                                if (currentTime.name === '冰冻') {
                                    offsetTime = DateUtil.offset({
                                        dateTime: DateUtil.parseDate(
                                            params.row.freezingDate
                                        ),
                                        hours: hour,
                                    });
                                } else {
                                    offsetTime = DateUtil.offset({
                                        dateTime: DateUtil.parseDate(
                                            params.row.createTime
                                        ),
                                        hours: hour,
                                    });
                                }

                                const day = new Date(offsetTime).getDay();
                                if (day === 6 || day === 0) {
                                    offsetTime = DateUtil.offset({
                                        dateTime: DateUtil.parseDate(
                                            params.row.createTime
                                        ),
                                        hours: hour + 48,
                                    });
                                }
                                dateContent = DateUtil.friendlyDate(
                                    offsetTime,
                                    '已超时'
                                );
                            }
                            return h('span', [
                                h(
                                    'el-tooltip',
                                    {
                                        attrs: {
                                            effect: 'dark',
                                            placement: 'top',
                                        },
                                    },
                                    [
                                        h('div', {
                                            attrs: { slot: 'content' },
                                            domProps: {
                                                innerHTML: dateContent
                                                    ? '送检时间 : ' +
                                                    params.row.createTime +
                                                    '</br>' +
                                                    '要求出报告时间 : ' +
                                                    offsetTime +
                                                    '</br>' +
                                                    '剩余时间 : ' +
                                                    dateContent.content +
                                                    '</br>'
                                                    : '',
                                            },
                                            slot: 'content',
                                        }),
                                        h(
                                            'span',
                                            {
                                                style: {
                                                    color:
                                                        !!dateContent &&
                                                            dateContent.isfuture
                                                            ? '#67C23A'
                                                            : '#F56C6C',
                                                },
                                            },
                                            !!dateContent
                                                ? dateContent.content
                                                : ''
                                        ),
                                    ]
                                ),
                            ]);
                        },
                    },
                    {
                        label: '分院名称',
                        prop: 'branchName',
                        width: '107',
                    },
                    {
                        label: '病理编号',
                        prop: 'pathologyId',
                        width: '107',
                    },
                    {
                        label: '状态',
                        prop: 'currentLevelLabel',
                        width: '96',
                        isRender: true,
                        render: (h, params) => {
                            let mColor =
                                params.row.currentLevel === 1
                                    ? '#909399'
                                    : params.row.currentLevel === 2 ||
                                        params.row.currentLevel === 3 ||
                                        params.row.currentLevel === 4 ||
                                        params.row.currentLevel === 5
                                        ? '#a5cbf0'
                                        : params.row.currentLevel === 6
                                            ? '#a3ea4d'
                                            : '';
                            let text = params.row.currentLevelLabel;
                            return h(
                                'span',
                                {
                                    style: {
                                        color: mColor,
                                    },
                                },
                                text
                            );
                        },
                    },

                    {
                        label: '标本类型',
                        prop: 'specimenTypeName',
                        width: '107',
                    },
                    {
                        label: '检查类型',
                        prop: 'checkCategoryName',
                        width: '107',
                    },
                    {
                        label: '诊断组',
                        prop: 'subspecialtyTypeName',
                        width: '107',
                    },
                    {
                        label: '切片AI',
                        prop: 'biopsyInfoIsAiList',
                        width: '92',
                    },
                    {
                        label: '临床AI',
                        width: '92',
                        prop: 'score',
                        isRender: true,
                        render: (h, params) => {
                            let score =
                                params.row.score === null
                                    ? 'grey'
                                    : params.row.score < 100 &&
                                        params.row.score >= 0
                                        ? 'green'
                                        : params.row.score >= 100
                                            ? 'red'
                                            : '';
                            return h('span', {
                                style: {
                                    display: 'block',
                                    width: '10px',
                                    height: '10px',
                                    borderRadius: '20px',
                                    margin: '0 auto',
                                    backgroundColor: score,
                                },
                            });
                        },
                    },
                    {
                        label: '综合分析',
                        width: '92',
                        isRender: true,
                        render: (h, params) => {
                            let sliceAi = null;
                            if (params.row.biopsyInfoIsAiList) {
                                if (
                                    params.row.biopsyInfoIsAiList.some(
                                        (obj) => {
                                            return obj.isAi == '2';
                                        }
                                    )
                                ) {
                                    sliceAi = 'red';
                                } else if (
                                    params.row.biopsyInfoIsAiList.some(
                                        (obj) => {
                                            return obj.isAi == '1';
                                        }
                                    )
                                ) {
                                    sliceAi = 'green';
                                } else {
                                    sliceAi = 'grey';
                                }
                            }
                            let nlpAi = null;
                            if (params.row.score == null) {
                                nlpAi = 'grey';
                            } else if (params.row.score >= 100) {
                                nlpAi = 'red';
                            } else if (
                                params.row.score < 100 &&
                                params.row.score >= 0
                            ) {
                                nlpAi = 'green';
                            }

                            let bgColorArr = [sliceAi, nlpAi];
                            let bgColor = '';
                            if (
                                bgColorArr.some((obj) => {
                                    return obj == 'red';
                                })
                            ) {
                                bgColor = 'red';
                            } else if (
                                bgColorArr.some((obj) => {
                                    return obj == 'green';
                                })
                            ) {
                                bgColor = 'green';
                            } else {
                                bgColor = 'grey';
                            }

                            return h('span', {
                                style: {
                                    display: 'block',
                                    width: '10px',
                                    height: '10px',
                                    borderRadius: '20px',
                                    margin: '0 auto',
                                    backgroundColor: bgColor,
                                },
                            });
                        },
                    },
                    {
                        label: '胃镜结论',
                        width: '118',
                        prop: 'gastroscopyAnalysisConclusion',
                        isRender: true,
                        render: (h, params) => {
                            let gastroscopyAnalysisConclusion = params.row
                                .gastroscopyAnalysisConclusion
                                ? params.row.gastroscopyAnalysisConclusion
                                : '';
                            let gastroscopyAnalysisConclusionSymptom = params
                                .row.gastroscopyAnalysisConclusionSymptom
                                ? params.row
                                    .gastroscopyAnalysisConclusionSymptom
                                : '';
                            return h('span', [
                                h(
                                    'el-tooltip',
                                    {
                                        attrs: {
                                            effect: 'dark',
                                            placement: 'left',
                                        },
                                    },
                                    [
                                        h('div', {
                                            attrs: { slot: 'content' },
                                            domProps: {
                                                innerHTML:
                                                    '胃镜AI : ' +
                                                    gastroscopyAnalysisConclusion +
                                                    '</br>' +
                                                    '胃镜结论 : ' +
                                                    gastroscopyAnalysisConclusionSymptom +
                                                    '</br>',
                                            },
                                            slot: 'content',
                                        }),
                                        h(
                                            'span',
                                            gastroscopyAnalysisConclusionSymptom
                                        ),
                                    ]
                                ),
                            ]);
                        },
                    },

                    {
                        label: '患者姓名',
                        prop: 'name',
                        width: '107',
                    },
                    {
                        label: '性别',
                        prop: 'sex',
                        width: '80',
                    },
                    {
                        label: '年龄',
                        prop: 'age',
                        width: '80',
                    },
                    {
                        label: '切片数',
                        prop: 'biopsyCount',
                        width: '94',
                    },
                    {
                        label: '已扫/总',
                        prop: 'biopsyCheck',
                        width: '100',
                        tooltip: {
                            name: 'nameSlot',
                            effect: 'dark',
                            placement: 'bottom',
                        },
                    },
                    {
                        label: '取材部位',
                        prop: 'sampleBody',
                        width: '107',
                        isRender: true,
                        render: (h, params) => {
                            let sampleBody = params.row.sampleBody
                                ? params.row.sampleBody
                                : '';
                            let sampleBodySymptom = params.row.sampleBody
                                ? `${params.row.sampleBody.slice(0, 5)}...`
                                : '';
                            return h('span', [
                                h(
                                    'el-tooltip',
                                    {
                                        attrs: {
                                            effect: 'dark',
                                            placement: 'left',
                                        },
                                    },
                                    [
                                        h('div', {
                                            attrs: { slot: 'content' },
                                            domProps: {
                                                innerHTML: sampleBody,
                                            },
                                            slot: 'content',
                                        }),
                                        h('span', sampleBodySymptom),
                                    ]
                                ),
                            ]);
                        },
                    },

                    {
                        label: '冰冻',
                        prop: 'freezeTypeName',
                        width: '80',
                    },
                    {
                        label: '切片质量',
                        width: '107',
                        isRender: true,
                        render: (h, params) => {
                            let biopsyQualityValue = '';
                            if (params.row.biopsyQualityInfoList) {
                                params.row.biopsyQualityInfoList.forEach(
                                    (item) => {
                                        if (item.biopsyQuality == null) {
                                        } else {
                                            biopsyQualityValue =
                                                biopsyQualityValue +
                                                item.biopsyQuality +
                                                ' ';
                                        }
                                    }
                                );
                            }
                            return h('span', biopsyQualityValue);
                        },
                    },
                    {
                        label: '清晰度',
                        width: '107',
                        isRender: true,
                        render: (h, params) => {
                            let scanDefinitionValue = '';
                            if (params.row.biopsyScanDefinitionInfoList) {
                                params.row.biopsyScanDefinitionInfoList.forEach(
                                    (item) => {
                                        if (item.scanDefinition == null) {
                                        } else {
                                            scanDefinitionValue =
                                                scanDefinitionValue +
                                                item.scanDefinition +
                                                ' ';
                                        }
                                    }
                                );
                            }
                            return h('span', scanDefinitionValue);
                        },
                    },
                    {
                        label: '送检科室',
                        prop: 'sendDepartment',
                        width: '107',
                    },
                    {
                        label: '送检医生',
                        prop: 'sendDoctor',
                        width: '107',
                    },
                    {
                        label: '扫描日期',
                        width: '136',
                        prop: 'createTime',
                        // isRender: true,
                        // render: (h, params) => {
                        //     let createTimeValue = '';
                        //     if (params.row.biopsyScanTimeInfoList) {
                        //         params.row.biopsyScanTimeInfoList.forEach(
                        //             (item) => {
                        //                 if (item.createTime == null) {
                        //                 } else {
                        //                     createTimeValue =
                        //                         createTimeValue +
                        //                         item.createTime +
                        //                         ' ';
                        //                 }
                        //             }
                        //         );
                        //     }
                        //     return h('span', createTimeValue);
                        // },
                    },
                    {
                        label: '扫描批次',
                        width: '107',
                        prop: 'biopsyHistoryIdInfoList',
                        isRender: true,
                        render: (h, params) => {
                            let scanBatchValue = '';
                            if (params.row.biopsyHistoryIdInfoList) {
                                params.row.biopsyHistoryIdInfoList.forEach(
                                    (item) => {
                                        if (item.biopsyHistoryId == null) {
                                        } else {
                                            scanBatchValue =
                                                scanBatchValue +
                                                item.biopsyHistoryId +
                                                ' ';
                                        }
                                    }
                                );
                            }
                            return h('span', scanBatchValue);
                        },
                    },
                    {
                        label: '退回原因',
                        prop: 'remark',
                        width: '107',
                    },
                ],
                operation: [
                    {
                        label: '认领',
                        functionKey: 'diagnosisTableAssign',
                    },
                    {
                        label: '详情',
                        functionKey: 'diagnosisTableDetail',
                    },
                    {
                        label: '退回',
                        color: 'red',
                        functionKey: 'diagnosisTableSendBack',
                    },
                ],
                pageInfo: {
                    // page: 1,
                    page: itemsDiagnosisListPage.get(),
                    size: itemsPerPage.get(),
                    total: 0,
                },
            },
            filterForm: {
                pathologyId: '',
                name: '',
                sampleOrganId: '', // 取材脏器
                sendDoctor: '', // 送检医生
                checkCategory: '', // 检查类型
                startAge: '',
                endAge: '',
                cardId: '',
                sex: '',
                allOrPersonal: 0, //任务池区分所有与我的
                wardId: '',
                bedId: '',
                sampleBody: '', // 取材部位
                sendDoctorTel: '', // 联系电话
                specimenName: '', // 标本名称
                specimenType: '', // 标本类别
                scanDateEnd: '', // 最小创建时间
                scanDateStart: '', // 最大创建时间
                biopsyHistoryId: '', //扫描批次
                biopsyCreateTime: '', //扫描日期
                currentLevel: '', //待写审超延印按钮筛选
            },
            createdRange: [],
            scanRange: [],
            showExpansion: false,
            checkCategoryList: [],
            sexKindList: [],
            specimenCategoryList: [],
            freezeAndCommonTimeList: [], // 保存冰冻常规对应的超时时间
            specimenCategoryTimeList: [], // 保存标本类别对应的超时时间
            allOrPersonalList: [
                {
                    id: 0,
                    name: '所有',
                },
                {
                    id: 1,
                    name: '我的',
                },
            ], //任务池所有与我的
            // 取材脏器列表
            sampleOrganList: [],
            // 所需字典对应表
            dictRequestMap: [
                {
                    code: 'checkCategory',
                    arrayKey: 'checkCategoryList',
                },
                {
                    code: 'specimenCategory',
                    arrayKey: 'specimenCategoryList',
                },
                {
                    code: 'freezeType',
                    arrayKey: 'freezeAndCommonTimeList',
                },
                {
                    code: 'specimenCategory',
                    arrayKey: 'specimenCategoryTimeList',
                },
                {
                    code: 'hospitalList',
                    arrayKey: 'hospitalList',
                },
            ],
            filterTemp: {},
            normalDetailDialog: {
                visible: false,
                pathologyId: '',
            },
            hospitalList: [],
            branchCourtsList: [], //分院列表
        };
    },
    mounted() {
        this.diagnosisCountRequest(); //获取 任务池 我的任务 我已承接角标
        this.consultationCountRequest(); //获取科内会诊与院外会诊的角标
        //全屏
        // this.screenFull();
        // this.tabActive();
        // this.diagnosisTableRequest();
        // 获取字典数据
        // this.dictionariesRequest();
        // 获取脏器数据
        // this.sampleOrganRequest();
    },
    computed: {
        //机构是否启用任务认领
        isEnableTaskClaim() {
            return _.get(
                this.$store.state,
                'institution.isEnableTaskClaim',
                false
            );
        },

        requestUrl() {
            if (this.listTabActive === 'divisionConsultation') {
                this.diagnosisTable.selected = false;
                return '/diagnosis/divisionConsultation';
            }
            if (this.listTabActive === 'outsideConsultation') {
                this.diagnosisTable.selected = false;
                return '/diagnosis/divisionConsultation';
            }
            if (this.listTabActive === 'waitingAssign') {
                this.diagnosisTable.selected = true;
                return '/diagnosis/wait-dispatch';
            }
            if (this.listTabActive === 'myIssues') {
                this.diagnosisTable.selected = false;
                return '/diagnosis/tasks';
            }
            if (this.listTabActive === 'myAssigned') {
                this.diagnosisTable.selected = false;
                return '/diagnosis/finished';
            }
            return '';
        },
    },
    methods: {
        goPc() {
            this.$router.push('/diagnosis/list')
        },
        toDataList(id) {
            this.$router.push(`/diagnosis/padDataList/${id}`)
        },

        //获取分院列表
        getBranchList(id) {
            this.branchCourtsList = []
            let mData = this.hospitalList.filter((item) => item.id === id)[0]
            if (mData.firstCode) {
                mData.firstCode.split('、').forEach((item) => {
                    this.branchCourtsList.push({ name: item })
                })
            }
        },
        wait() {
            this.filterForm.isTimeout = '';
            this.filterForm.currentLevel = '1';
            this.search();
        },
        write() {
            this.filterForm.isTimeout = '';
            this.filterForm.currentLevel = '2,3,4,5';
            this.search();
        },
        check() {
            this.filterForm.isTimeout = '';
            this.filterForm.currentLevel = '6';
            this.search();
        },
        delay() { },
        timeout() {
            this.filterForm.isTimeOut = '1';
            this.filterForm.currentLevel = '';
            this.search();
        },
        print() { },
        setFilterFormNull() {
            this.filterForm = {
                pathologyId: '',
                name: '',
                sampleOrganId: '', // 取材脏器
                sendDoctor: '', // 送检医生
                checkCategory: '', // 检查类型
                startAge: '',
                endAge: '',
                cardId: '',
                sex: '',
                allOrPersonal: 0, //任务池区分所有与我的
                wardId: '',
                bedId: '',
                sampleBody: '', // 取材部位
                sendDoctorTel: '', // 联系电话
                specimenName: '', // 标本名称
                specimenType: '', // 标本类别
                scanDateEnd: '', // 最小创建时间
                scanDateStart: '', // 最大创建时间
                biopsyHistoryId: '', //扫描批次
                biopsyCreateTime: '', //扫描日期
                currentLevel: '', //待写审超延印按钮筛选
            };
            this.search();
        },
        screenFull() {
            if (this.$store.state.fullScreen) {
                if (
                    !document.fullscreenElement &&
                    !document.msFullscreenElement &&
                    !document.mozFullScreenElement &&
                    !document.webkitFullscreenElement
                ) {
                    let docElm = document.documentElement;
                    if (docElm.requestFullscreen) {
                        docElm.requestFullscreen();
                    } else if (docElm.msRequestFullscreen) {
                        // IE
                        docElm = document.body; // overwrite the element (for IE)
                        docElm.msRequestFullscreen();
                    } else if (docElm.mozRequestFullScreen) {
                        // 火狐
                        docElm.mozRequestFullScreen();
                    } else if (docElm.webkitRequestFullScreen) {
                        // 谷歌
                        docElm.webkitRequestFullScreen();
                    }
                    //设置是否全屏
                    this.$store.commit('fullScreenChange', false);
                }
            }
        },
        tabActive() {
            this.listTabActive =
                this.$store.state.itemsDiagnosisListTabChangePage;
        },
        becomeFullScreen() {
            if (this.isFullScreen) {
                this.isFullScreen = false;
            } else {
                this.isFullScreen = true;
            }
        },
        allOrPersonalChange(val) {
            this.search();
        },
        listTabChange(tab, event) {
            itemsDiagnosisListPage.set(1); // 重置页码
            this.diagnosisTable.pageInfo.page = 1; // console.log(tab.name);
            this.$store.commit('itemsDiagnosisListTabChange', tab.name);
            this.filterTemp.currentLevel = '';
            this.diagnosisTableRequest();
        },
        diagnosisTableButtonClick(functionKey, row) {
            this[functionKey](row);
        },
        // 认领
        async diagnosisTableAssign(row) {
            let value = row.biopsyCheck.split('/');
            let numerator = value[0];
            let denominator = value[1];
            let txtMessage = '';
            if (numerator / denominator <= 1) {
                txtMessage = `还有${denominator - numerator}张未扫描`;
            }
            const { state } = this.$store;
            await this.$axios({
                url: `/PROXY-Remote/diagnosis/${row.id}/next-flow`,
                method: 'PUT',
                data: {
                    doctorId: state.user.id,
                    isTempStorage: 0,
                },
            }).then((res) => {
                if (res.data.code === 200) {
                    // 请求成功
                    this.$message.success('认领成功!' + txtMessage);
                    this.diagnosisTableRequest();
                } else {
                    this.$message.warning(res.data.message);
                }
            });
        },
        diagnosisTableDetail(row) {
            let commitValue = {
                id: row.id,
                pathologyId: row.pathologyId,
                pDiagnosisType: '',
            };
            if (this.listTabActive === 'myIssues') {
                commitValue.pDiagnosisType = 1; //我的任务传0，给/diagnosis/single这个接口的参数 区分是从我的任务点进去的详情，得到上一个下一个病理号，切片浏览器上z,x快捷键才能用
            } else if (this.listTabActive === 'myAssigned') {
                commitValue.pDiagnosisType = 2; //我已承接传1，给/diagnosis/single这个接口的参数 区分是从我的任务点进去的详情，得到上一个下一个病理号，切片浏览器上z,x快捷键才能用
            } else if (this.listTabActive === 'waitingAssign') {
                commitValue.pDiagnosisType = 0; //任务池 给/diagnosis/single这个接口的参数 区分是从我的任务点进去的详情，得到上一个下一个病理号，切片浏览器上z,x快捷键才能用
            } else {
                commitValue.pDiagnosisType = '';
            }
            sessionStorage.setItem('diagnosisType', row.diagnosisType); //被邀请的医生点击暂存或者复制加上此参数

            //留言讨论发送接口是根据此条记录的diagnosisId进行请求的
            if (this.listTabActive === 'divisionConsultation') {
                this.normalDetailDialog.pathologyId = row.pathologyId;
                this.normalDetailDialog.visible = true;
            }

            this.$store.commit('setPropertyGeneral', {
                key: 'diagnosis',
                value: commitValue,
            });
            sessionStorage.setItem(
                'pDiagnosisType',
                commitValue.pDiagnosisType
            );
            sessionStorage.setItem('pathologyId', commitValue.pathologyId);
            if (this.listTabActive === 'divisionConsultation') {
                return;
            } else {
                this.$router.push('/diagnosis/detail');
            }
        },
        // 退回
        diagnosisTableSendBack(row) {
            this.$prompt('请输入退回说明', '退回说明', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputPattern: /.*[^\s]/,
                inputErrorMessage: '退回说明不能为空',
            })
                .then(async ({ value }) => {
                    const res = await this.$axios({
                        method: 'PUT',
                        url: `/PROXY-Remote/diagnosis/${row.id}/send-back`,
                        params: {
                            remark: value,
                        },
                    });
                    if (res && res.data.code === 200) {
                        this.$message.success('退回成功');
                        this.diagnosisTableRequest();
                    } else {
                        this.$message.warning('退回失败');
                    }
                })
                .catch(() => {
                    this.$message.info('取消操作');
                });
        },
        diagnosisTablePageJumpTo(val) {
            itemsDiagnosisListPage.set(val);
            this.diagnosisTable.pageInfo.page = val;
            // 为 diagnosisTable.data 赋值相应页上新数据
            this.diagnosisTableRequest();
        },
        diagnosisTableSizeChange(val) {
            this.diagnosisTable.pageInfo.size = val;
            // 为 diagnosisTable.data 赋值相应数据量新数据
            this.diagnosisTableRequest();
        },
        diagnosisTableButtonVisibleFunc(functionKey) {
            switch (functionKey) {
                case 'diagnosisTableAssign':
                    return this.listTabActive === 'waitingAssign';
                case 'diagnosisTableSendBack':
                    return this.listTabActive === 'myIssues';
                default:
                    return true;
            }
        },
        diagnosisTableCellStyleFunc({ row, column }) {
            const baseStyle = {
                padding: '3px 0',
                'border-right': '1px solid #ffffff',
                'font-size': '14px',
            };
            switch (column.label) {
                case '性别':
                    if (row.sex === '女性') {
                        baseStyle.color = 'red';
                    }
                    if (row.sex === '男性') {
                        baseStyle.color = 'blue';
                    }
                    break;
                case '已扫/总':
                    if (row.biopsyCheckColor == '#10a1df') {
                        baseStyle.color = '#10a1df';
                    } else if (row.biopsyCheckColor == 'red') {
                        baseStyle.color = 'red';
                    } else {
                        baseStyle.color = '#666666';
                    }
                    break;
            }
            return baseStyle;
        },
        async diagnosisTableRequest() {
            if (this.listTabActive === 'divisionConsultation') {
                this.filterTemp.judgeDivisionOrOutside = 0; //该参数如果传0时，代表科内，传1时，代表院外
            } else if (this.listTabActive === 'outsideConsultation') {
                this.filterTemp.judgeDivisionOrOutside = 1; //该参数如果传0时，代表科内，传1时，代表院外
            } else {
                this.filterTemp.judgeDivisionOrOutside = '';
            }
            if (this.listTabActive === 'waitingAssign') {
                this.filterTemp.allOrPersonal = this.filterForm.allOrPersonal;
            } else {
                this.filterTemp.allOrPersonal = '';
            }
            this.diagnosisTable.isReady = false;
            this.filterTemp.size = this.diagnosisTable.pageInfo.size;
            this.filterTemp.page = this.diagnosisTable.pageInfo.page - 1;

            const res = await this.$axios({
                url: `/PROXY-Remote${this.requestUrl}`,
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                params: {
                    isShowDispatcher: 0,
                },
                data: this.filterTemp,
            });
            if (res && res.data.code !== 200) {
                this.diagnosisTable.isReady = true;
                throw new Error(res.data);
            }
            this.diagnosisCountRequest(); //获取 任务池 我的任务 我已承接角标
            this.consultationCountRequest(); //获取科内会诊与院外会诊的角标
            // 请求成功
            const result = res.data;
            // 分页信息
            this.diagnosisTable.pageInfo = {
                total: result.pageInfo.total,
                page: result.pageInfo.page + 1,
                size: result.pageInfo.size,
            };
            // 查询结果数据
            this.diagnosisTable.data = [];
            if (result.data) {
                result.data.forEach((t) => {
                    this.diagnosisTable.data.push({
                        index: this.diagnosisTable.data.length,
                        id: t.id,
                        createTime: t.createTime,
                        currentLevel: t.currentLevel,
                        currentLevelLabel:
                            t.currentLevelLabel +
                            this.getComposeValue(t.diagnosisType),
                        diagnosisType: t.diagnosisType, //是否被邀请
                        pathologyId: t.pathologyId,
                        biopsyCount: t.biopsyList.length,
                        biopsyCheck: t.biopsyCheck,
                        biopsyInfoIsAiList: t.biopsyInfoIsAiList,
                        name: t.name,
                        sendDoctor: t.sendDoctor,
                        age: t.age == null ? '' : t.age + t.ageUnitName,
                        sex: t.sexName,
                        sendDepartment: t.sendDepartment,
                        sampleBody: t.sampleBody,
                        sampleOrganName: t.sampleOrganName,
                        biopsyHistoryId: t.biopsyHistoryId,
                        biopsyCreateTime: t.biopsyCreateTime,
                        freezeTypeName: t.freezeTypeName,
                        specimenTypeName: t.specimenTypeName,
                        checkCategoryName: t.checkCategoryName,
                        subspecialtyTypeName: t.subspecialtyTypeName,
                        scanDefinition: t.scanDefinition,
                        biopsyQuality: t.biopsyQuality,
                        createTime: t.createTime,
                        biopsyHistoryIdInfoList: t.biopsyHistoryIdInfoList,
                        biopsyQualityInfoList: t.biopsyQualityInfoList,
                        biopsyScanDefinitionInfoList:
                            t.biopsyScanDefinitionInfoList,
                        gastroscopyAnalysisConclusion:
                            t.gastroscopyAnalysisConclusion,
                        gastroscopyAnalysisConclusionSymptom:
                            t.gastroscopyAnalysisConclusionSymptom,
                        score: t.score,
                        branchName: t.branchName,
                        remark: t.remark,
                    });
                });
            }
            this.addColor(this.diagnosisTable.data);
            this.diagnosisTable.isReady = true;

            // console.log(
            //     'this.diagnosisTable.data------',
            //     this.diagnosisTable.data
            // );
            // console.log(
            //     'this.$store.state.itemsDiagnosisListRowClickId----',
            //     this.$store.state.itemsDiagnosisListRowClickId
            // );
            // let rowClickIndex = this.diagnosisTable.data.findIndex((item) => {
            //     return (
            //         item.id === this.$store.state.itemsDiagnosisListRowClickId
            //     );
            // });
            // console.log('rowClickIndex', rowClickIndex);

        },

        getComposeValue(diagnosisType) {
            return diagnosisType === null || diagnosisType === 0
                ? ''
                : diagnosisType === 1
                    ? '(被邀请)'
                    : '';
        },

        //返回的数据给扫描确认加颜色
        addColor(shuju) {
            shuju.forEach((item) => {
                let biopsyChecks = item.biopsyCheck.split('/');
                item.biopsyCheckColor =
                    Number(biopsyChecks[0]) < Number(biopsyChecks[1])
                        ? '#10a1df'
                        : Number(biopsyChecks[0]) > Number(biopsyChecks[1])
                            ? 'red'
                            : '#666666';
            });
        },
        //角标数据
        diagnosisCountRequest() {
            this.tabCountRequestList.forEach(async (t) => {
                try {
                    await this.$axios({
                        url: `/PROXY-Remote${t.url}`,
                        method: 'POST',
                        headers: {
                            'Content-Type': 'application/json',
                        },
                        params: {
                            isShowDispatcher: 0,
                        },
                        data: {
                            size: 10,
                            page: 0,
                        },
                    }).then((res) => {
                        // 请求失败
                        if (res.data.code !== 200) {
                            throw new Error(res.data);
                        }
                        const result = res.data;
                        // 请求成功
                        this[t.countKey] = result.pageInfo.total;
                    });
                } catch (e) {
                    // 跳出
                }
            });
        },

        //科内会诊与院外会诊角标数
        consultationCountRequest() {
            this.consultationRequestList.forEach(async (t) => {
                try {
                    await this.$axios({
                        url: `/PROXY-Remote${t.url}`,
                        method: 'POST',
                        headers: {
                            'Content-Type': 'application/json',
                        },
                        params: {
                            isShowDispatcher: 0,
                        },
                        data: {
                            judgeDivisionOrOutside: t.judgeDivisionOrOutside,
                            size: 10,
                            page: 0,
                        },
                    }).then((res) => {
                        // 请求失败
                        if (res.data.code !== 200) {
                            throw new Error(res.data);
                        }
                        const result = res.data;
                        // 请求成功
                        this[t.countKey] = result.pageInfo.total;
                    });
                } catch (e) {
                    // 跳出
                }
            });
        },
        // 请求字典信息
        dictionariesRequest() {
            this.dictRequestMap.forEach((map) => {
                this.$axios({
                    method: 'GET',
                    url: '/PROXY-Remote/dicts/list',
                    params: {
                        code: map.code,
                        page: 0,
                        size: 99,
                    },
                }).then((res) => {
                    if (res && res.data.code === 200) {
                        this[map.arrayKey] = _.clone(res.data.data);

                        if (map.code === 'SexKind') {
                            this[map.arrayKey].push({
                                id: '',
                                name: '全部',
                            });
                        }
                    }
                });
            });
        },
        // 请求脏器信息
        sampleOrganRequest() {
            this.$axios({
                // 详见 axios 请求配置项
                method: 'GET',
                url: '/PROXY-Remote/organs',
                params: {
                    size: 10000,
                },
            }).then((res) => {
                if (res && res.data.code === 200) {
                    res.data.data.forEach((t) => {
                        this.sampleOrganList.push({
                            id: t.id,
                            name: t.name,
                        });
                    });
                }
            });
        },
        // 对年龄进行判断
        ageValidate() {
            // 判断年龄格式
            if (this.filterForm.startAge) {
                const age = _.toNumber(this.filterForm.startAge);
                if (typeof age !== 'number' || Number.isNaN(age)) {
                    this.$message.warning('年龄必须为数字！');
                    return false;
                }
            }
            if (this.filterForm.endAge) {
                const age = _.toNumber(this.filterForm.endAge);
                if (typeof age !== 'number' || Number.isNaN(age)) {
                    this.$message.warning('年龄必须为数字！');
                    return false;
                }
            }
            // 判断年龄范围
            if (this.filterForm.startAge && this.filterForm.endAge) {
                if (this.filterForm.startAge >= this.filterForm.endAge) {
                    this.$message.warning('起始年龄应该小于结束年龄!');
                    return false;
                }
            }
            return true;
        },
        search() {
            if (!this.ageValidate()) {
                return false;
            }
            // 确定时间范围
            if (this.createdRange && this.createdRange.length > 0) {
                let createTimeStart = '';
                let createTimeEnd = '';
                [createTimeStart, createTimeEnd] = this.createdRange;
                this.filterForm.creatDateStart = moment(createTimeStart)
                    .format('YYYY-MM-DD hh:mm:ss')
                    .replace(' ', ' ');
                this.filterForm.creatDateEnd = moment(createTimeEnd)
                    .format('YYYY-MM-DD hh:mm:ss')
                    .replace(' ', ' ');
            } else {
                this.filterForm.creatDateStart = '';
                this.filterForm.creatDateEnd = '';
            }
            if (this.scanRange && this.scanRange.length > 0) {
                let scanTimeStart = '';
                let scanTimeEnd = '';
                [scanTimeStart, scanTimeEnd] = this.scanRange;
                this.filterForm.scanDateStart = moment(scanTimeStart)
                    .format('YYYY-MM-DD hh:mm:ss')
                    .replace(' ', ' ');
                this.filterForm.scanDateEnd = moment(scanTimeEnd)
                    .format('YYYY-MM-DD hh:mm:ss')
                    .replace(' ', ' ');
            } else {
                this.filterForm.scanDateStart = '';
                this.filterForm.scanDateEnd = '';
            }

            // 保存过滤条件到 Temp
            this.filterTemp = {};
            Object.keys(this.filterForm).forEach((key) => {
                if (this.filterForm[key]) {
                    this.filterTemp[key] = this.filterForm[key];
                }
            });
            this.filterTemp.page = 0;
            // 重置页码
            this.diagnosisTable.pageInfo.page = 1;
            this.diagnosisTableRequest();
            return true;
        },
        selectionChange(selection) {
            this.selectedList = selection;
        },
        handleSelectAll(row) {
            this.selectedList = row;
        },
        // 批量认领任务
        async batchClaim() {
            if (this.selectedList.length !== 0) {
                const { state } = this.$store;
                await this.$axios({
                    method: 'POST',
                    url: '/diagnosis/next-flows',
                    data: {
                        doctorId: state.user.id,
                        diagnosisIds: _.map(this.selectedList, 'id'),
                        isTempStorage: 0,
                    },
                }).then((res) => {
                    if (res.data.code === 409) {
                        this.$message.warning(res.data.message);
                    } else if (res && res.data.code === 200) {
                        this.diagnosisTableRequest();
                        this.$message.success('批量认领成功');
                    }
                });
            } else {
                this.$message.warning('请选择要认领的任务');
            }
        },
        //全部认领任务 触发git提交此文件
        // async allClaim() {
        //     this.$confirm("确认全部认领", "提示", {
        //         confirmButtonText: "确定",
        //         cancelButtonText: "取消",
        //         type: "warning",
        //     })
        //         .then(() => {
        //             this.$axios({
        //                 method: "POST",
        //                 url: "/diagnosis/all/next-flows",
        //                 data: {},
        //             }).then((res) => {
        //                 if (res && res.data.code === 200) {
        //                     this.diagnosisTableRequest();
        //                     this.$message.success("全部认领成功");
        //                 }
        //             });
        //         })
        //         .catch();
        // },
    },
};
</script>

<style scoped>
.pad-box {
  display: flex;
  flex-wrap: wrap;
}

.bg-purple {
  display: flex;
  justify-content: space-between;
  width: 231px;
  height: 141px;
  background: #f5f8fa;
  box-shadow: 0px 4px 10px 0px rgba(0, 0, 0, 0.1);
  border-radius: 16px 16px 16px 16px;
  opacity: 1;
  border: 1px solid #efefef;
  padding: 20px;
  margin: 20px;
}

.bg-purple .box-left {
  display: flex;
  flex-direction: column;
}

.bg-purple .box-left span {
  font-size: 30px;
  font-family: Source Han Sans CN-Regular, Source Han Sans CN;
  font-weight: 400;
  color: #3d3d3d;
  line-height: 76px;
}

.num span {
  font-size: 100px;
  font-family: D-DIN-Bold, D-DIN;
  font-weight: 700;

  line-height: 160px;
}

.redClass {
  color: #fb0f0f;
}

.normalClass {
  color: #bdbdbd;
}

.blueClass {
  color: #0fa9fb;
}

.bg-purple .box-left img {
  width: 64px;
}

.tab-content-badge {
    top: 3px;
}

.expansion {
    width: 30px;
    height: 30px;
    display: inline;
    font-size: 28px;
    line-height: 30px;
    margin-top: 25px;
    vertical-align: middle;
    color: #10a1df;
    cursor: pointer;
}

.link-line {
    text-align: center;
}

.time-picker {
    width: auto;
}

/deep/ .el-dialog {
    margin: 0 auto 50px !important;
    min-height: 800px;
}
@media only screen and (max-width: 1000px) {
    .bg-purple{width: 141px;height: 70px;}
    .bg-purple .box-left span{font-size: 18px;}
    .bg-purple .box-left img{width: 32px;}
    .num span{font-size: 50px;line-height: 80px;}

}
</style>
